package com.star.mall.persistence.entity;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.star.mall.base.model.BaseModel;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 用户积分表
 * </p>
 *
 * @author StarQ
 * @since 2021-08-02
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("uc_user_score")
@ApiModel(value="UserScore对象", description="用户积分表")
public class UserScore extends BaseModel {

    private static final long serialVersionUID = 1L;

    //收入
    public static final int INCOME = 1;
    //支出
    public static final int OUTCOME = 2;

    @ApiModelProperty(value = "用户ID")
    @TableField("USER_ID_")
    private String userId;

    @ApiModelProperty(value = "积分数")
    @TableField("SCORE_")
    private Integer score;

    @ApiModelProperty(value = "积分类型")
    @TableField("TYPE_")
    private Integer type;

    @ApiModelProperty(value = "来源")
    @TableField("SCORE_SRC_")
    private Integer scoreSrc;

    @ApiModelProperty(value = "来源ID")
    @TableField("SRC_ID_")
    private String srcId;

    @ApiModelProperty(value = "来源描述")
    @TableField("SRC_REMARKS_")
    private String srcRemarks;

    public int getModifyScore() {
        if (BeanUtil.isEmpty(score)) {
            return 0;
        }
        if (INCOME == type) {
            return score;
        }else {
            return -score;
        }
    }

}
